﻿using Coldairarrow.Business.MEGA;
using Coldairarrow.Entity.MEGA;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.MEGA
{
    [Route("/MEGA/[controller]/[action]")]
    public class MEGA_LeafBladeAndQrCodeController : BaseApiController
    {
        #region DI

        public MEGA_LeafBladeAndQrCodeController(IMEGA_LeafBladeAndQrCodeBusiness mEGA_LeafBladeAndQrCodeBus)
        {
            _mEGA_LeafBladeAndQrCodeBus = mEGA_LeafBladeAndQrCodeBus;
        }

        IMEGA_LeafBladeAndQrCodeBusiness _mEGA_LeafBladeAndQrCodeBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<MEGA_LeafBladeAndQrCode>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _mEGA_LeafBladeAndQrCodeBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<MEGA_LeafBladeAndQrCode> GetTheData(IdInputDTO input)
        {
            return await _mEGA_LeafBladeAndQrCodeBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(MEGA_LeafBladeAndQrCode data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _mEGA_LeafBladeAndQrCodeBus.AddDataAsync(data);
            }
            else
            {
                await _mEGA_LeafBladeAndQrCodeBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _mEGA_LeafBladeAndQrCodeBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}